package com.dragon.client.controller.avttendance;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.logical.service.avttendance.IAttendanceReplaceService;
import com.dragon.repository.domain.dto.AttendanceReplaceDTO;
import com.dragon.repository.domain.vo.AttendanceReplaceVO;
import com.dragon.repository.entity.AttendanceReplace;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 补卡表 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-08-15
 */
@RestController
@RequestMapping("attendanceReplace")
@Api(tags = "考勤补卡")
public class AttendanceReplaceController {

    @Autowired
    IAttendanceReplaceService service;

    @GetMapping("list")
    @ApiOperation("补卡列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminId", value = "用户id", required = false, type = "int"),
            @ApiImplicitParam(name = "page", value = "页码", required = true, type = "int"),
            @ApiImplicitParam(name = "limit", value = "条数", required = true, type = "int")
    })
    public ResponseData<List<AttendanceReplaceDTO>> replaceList(Integer adminId, Integer page, Integer limit){
        Page<AttendanceReplace> replacePage = service.replaceList(adminId, page, limit);
        return ResponseData.success(AttendanceReplaceDTO.convertList(replacePage.getRecords()), replacePage.getTotal());
    }

    @PostMapping("add")
    @ApiOperation("补卡")
    public ResponseData addReplace(@RequestBody @Validated(Insert.class)AttendanceReplaceVO vo){
        service.addReplace(AttendanceReplaceVO.convert(vo));
        return ResponseData.success();
    }



}
